﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class export_myScoreExport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //只显示学生选了课的考试
        string course_id = "";
        string course_name = "";
        //Session["student_id"] = "3120182109222";
        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数

        try
        {
            //填充数据
            int page = Int32.Parse(Request.QueryString["page"].ToString().Trim());
            int limit = Int32.Parse(Request.QueryString["limit"].ToString().Trim());
            if (Request.QueryString["course_id"] != null)
            {
                course_id = Request.QueryString["course_id"].ToString().Trim();
            }
            if (Request.QueryString["course_name"] != null)
            {
                course_name = Request.QueryString["course_name"].ToString().Trim();
            }

            
            List<string> wheres = new List<string>();
            List<string> wheres1 = new List<string>();        //为搜索服务的
            if (course_id != "")
            {
                wheres.Add("course_id like '%" + course_id + "%'");
                wheres1.Add("b.course_id like '%" + course_id + "%'");
            }
            if (course_name != "")
            {
                wheres.Add("course_name like '%" + course_name + "%'");
                wheres1.Add("b.course_name like '%" + course_name + "%'");
            }
            string wh = "";
            if (wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                
            }
            
            string wh1 = "";
            if (wheres1.Count > 0)
            {
                wh1 = string.Join(" and ", wheres1.ToArray());
               
            }
            string sql = "select test_question_id,c.test_question_name, a.course_id,b.course_name ,a.test_score from tb_score as a inner join  tb_course as b on a.course_id = b.course_id "
                        + " inner join tb_test_questions as c on b.course_id =c.course_id where student_id  =   '" + Session["student_id"] + "'";
            if (wheres.Count > 0)
            {
                sql = sql + " and  " + wh1 ;
            }
           
            table1 = SqlServer.GetDataTable(sql);
        }
        catch (Exception ex)
        {
            Response.Write("-1");
            Response.End();
        }
        Response.Write(Json.ToJson(table1, count));
        Response.End();

    }


}
